*Get types*

clear

use "Data\dataset_with_singles.dta" 

merge 1:1 pnr aar using "Results\tab_B1\Scenario_3\life_earnings_ambition.dta", keepusing(life_earnings_ambition)

drop if _merge==2
drop _merge

* First condition on the ambition type sample

gen inambition = 0
replace inambition = 1 if ambition_type_k_4_s!=.

cap drop temp2
gen temp2=koen if relationship==1 & inambition == 1
destring temp2, replace
cap drop temp3
by couple_id aar, sort: egen temp3=mean(temp2)

cap drop inambition
gen inambition = 0 
replace inambition = 1 if relationship==0 & ambition_type_k_4_s!=.
replace inambition = 1 if relationship==1 & ambition_type_k_4_s!=. & temp3==1.5

keep if inambition == 1 

* Second, find all eligible singles and couples with lifetime earnings types

gen insample = 0
replace insample = 1 if life_earnings_ambition!=.

cap drop temp2
gen temp2=koen if relationship==1 & insample == 1
destring temp2, replace
cap drop temp3
by couple_id aar, sort: egen temp3=mean(temp2)

cap drop insample
gen insample = 0 
replace insample = 1 if relationship==0 & life_earnings_ambition!=.
replace insample = 1 if relationship==1 & life_earnings_ambition!=. & temp3==1.5

*Only keep those with non missing life time earnings ambition types*

keep if insample == 1

drop temp2 temp3 insample inambition

sort pnr aar



**Save**
save "Results\tab_B1\Scenario_3\data_with_types_ben.dta", replace